import 'package:flutter/material.dart';
import 'package:flutterhello/controller/Controller.dart';
import 'package:flutterhello/pages/login/login.dart';
import 'package:get/get.dart';

class SettingPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        child: AppBar(
          title: Text('设置'),
          centerTitle: true,
        ),
        preferredSize: Size.fromHeight(50),
      ),
      body: GetBuilder<Controller>(
        init: Controller(),
        builder: (controller) {
          return Padding(
            padding: EdgeInsets.all(10),
            child: GestureDetector(
                child: Container(
                  height: 50,
                  width: double.infinity,
                  decoration: BoxDecoration(
                    color: Colors.blueGrey,
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                  ),
                  child: Center(
                    child: Text(
                      '退出登录',
                      style: TextStyle(color: Colors.white, fontSize: 20),
                    ),
                  ),
                ),
                onTap: () async {
                  var result = await showDialog(
                      context: context,
                      builder: (context) {
                        return AlertDialog(
                          title: Text('提示'),
                          content: Text('确认退出吗？'),
                          actions: <Widget>[
                            TextButton(
                              child: Text('取消'),
                              onPressed: () {
                                Navigator.of(context).pop('cancel');
                              },
                            ),
                            TextButton(
                              child: Text('确认'),
                              onPressed: () async {
                                Navigator.of(context).pop('ok');
                                controller.userLogout();
                              },
                            ),
                          ],
                        );
                      });
                  print('$result');
                }),
          );
        },
      ),
    );
  }
}
